home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / demos / GL / curve / control.c next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  6.1 KB  |  346 lines

  1. /*
  2.  * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*
  18.  *
  19.  * control.c
  20.  * 
  21.  * Part of the "Curve Demo"
  22.  * by Howard Look for Silicon Graphics
  23.  *
  24.  * June, 1989
  25.  *
  26.  * This file contains the routines used for the program's display and
  27.  * environment options, as defaults and as selected by the user. Most
  28.  * of these routines are called by menu selection. See the file menu.c
  29.  * for menu derfinitions.
  30.  *
  31.  */
  32.  
  33.  
  34. #include <stdio.h>
  35. #include <gl.h>
  36. #include <device.h>
  37. #include <math.h>
  38. #include "curve.h"
  39. #include "event.h"
  40.  
  41.  
  42. /* Prototypes */
  43. void set_initial_conditions(void);
  44. void set_defaults(void);
  45. void change_display(int);
  46. void toggle_markers(void);
  47. void toggle_hulls(void);
  48. void toggle_motion(void);
  49. void toggle_smear(void);
  50. void change_basis(int);
  51. void change_precision(int);
  52. void change_speed(int);
  53. void change_style(int);
  54. void change_whizbang(int);
  55. void set_two_d_view(void);
  56. void set_three_d_view(void);
  57.  
  58. extern void clear_window(void);
  59. extern void remake_curve_menu(void);
  60. extern void remake_basis_menu(void);
  61. extern void remake_display_menu(void);
  62. extern void remake_precision_menu(void);
  63. extern void remake_speed_menu(void);
  64. extern void remake_style_menu(void);
  65. extern void remake_whizbang_menu(void);
  66. extern void remake_options_menu(void);
  67. extern void remake_all_menus(void);
  68. extern void create_whizbang(int);
  69.  
  70.  
  71. /* Environment variables */
  72. extern 
  73. int        curve_basis, 
  74.         display_mode, 
  75.         curve_precision,
  76.         speed, 
  77.         line_style, 
  78.         whizbang;
  79. extern
  80. Boolean    markers,
  81.         hulls, 
  82.         motion, 
  83.         smear,
  84.         rotating;
  85.  
  86. extern
  87. int hardware;
  88.  
  89.  
  90. /* About the window... */ 
  91. extern int origin_x, origin_y, size_x, size_y;
  92. extern float aspect;
  93.  
  94. extern Boolean draw_active;
  95.  
  96.  
  97. /*
  98.  * Sets default values for the environment variables. Change these to
  99.  * your heart's content.
  100.  */
  101. void set_initial_conditions(void)
  102. {
  103.     curve_basis = BSPLINE;
  104.     curvebasis(curve_basis);
  105.  
  106.     display_mode = TWO_D;
  107.     ortho(-1.0, 1.0, -1.0, 1.0, -2.0, 2.0);
  108.         
  109.     markers = ON;
  110.     hulls = OFF;
  111.     motion = OFF;
  112.     rotating = FALSE;
  113.  
  114.     curve_precision = MAX_PRECISION;
  115.     curveprecision(curve_precision);
  116.  
  117.     speed = DEFAULT_SPEED;
  118.     smear = OFF;
  119.     frontbuffer(FALSE);
  120.  
  121.     line_style = SOLID;
  122.     setlinestyle(line_style);
  123. }
  124.  
  125.  
  126. void set_defaults(void)
  127. {
  128.     set_initial_conditions();
  129.     remake_all_menus();
  130.     draw_display();
  131. }
  132.  
  133.  
  134.  
  135. /*
  136.  * Toggles the display mode between two and three dimensional
  137.  */
  138. void change_display(int new_mode)
  139. {
  140.     display_mode = new_mode;
  141.  
  142.     if (smear)
  143.     {
  144.         cpack(0); clear(); zclear();
  145.     }
  146.     
  147.     draw_display();
  148.     
  149.     remake_display_menu();
  150.     remake_curve_menu();
  151. }
  152.  
  153.  
  154. /* 
  155.  * Toggles the mode of the control point markers between on and off.
  156.  */
  157. void toggle_markers(void)
  158. {
  159.     if (markers == ON)
  160.         markers = OFF;
  161.     else
  162.         markers = ON;
  163.  
  164.     draw_display();
  165.     
  166.     remake_options_menu();
  167.     remake_curve_menu();
  168. }
  169.  
  170.  
  171. /* 
  172.  * Toggles the mode of the convex hulls between on and off.
  173.  */
  174. void toggle_hulls(void)
  175. {
  176.     if (hulls == ON)
  177.         hulls = OFF;
  178.     else
  179.         hulls = ON;
  180.  
  181.     draw_display();
  182.     
  183.     remake_options_menu();
  184.     remake_curve_menu();
  185. }
  186.  
  187.  
  188. /*
  189.  * Toggles motion between on and off.
  190.  */
  191. void toggle_motion(void)
  192. {
  193.     if (motion == ON)
  194.     {
  195.         motion = OFF;
  196.         draw_active = FALSE;
  197.     }
  198.     else
  199.     {
  200.         motion = ON;
  201.         draw_active = TRUE;
  202.     }
  203.  
  204.     remake_options_menu();
  205.     remake_curve_menu();
  206. }
  207.  
  208.  
  209. /* 
  210.  * Toggles 'smearing' between on and off. Smearing is only visible
  211.  * when motion is also turned on.
  212.  */
  213. void toggle_smear(void)
  214. {
  215.     if (smear == ON)
  216.     {
  217.         smear = OFF;
  218.         frontbuffer(FALSE);
  219.     }
  220.     else
  221.     {
  222.         smear = ON;
  223.         frontbuffer(TRUE);
  224.     }
  225.  
  226.     draw_display();
  227.  
  228.     remake_options_menu();
  229.     remake_curve_menu();
  230. }
  231.  
  232.  
  233. /*
  234.  * Changes the curve basis matrix to that selected by the user.
  235.  */
  236. void change_basis(int new_basis)
  237. {
  238.     curve_basis = new_basis;
  239.  
  240.     curvebasis(curve_basis);
  241.  
  242.     draw_display();
  243.     
  244.     remake_basis_menu();
  245.     remake_curve_menu();
  246. }
  247.  
  248.  
  249. /*
  250.  * Changes the curve precision (in segments per spline) to that
  251.  * selected by the user.
  252.  */
  253. void change_precision(int new_precision)
  254. {
  255.     curve_precision = new_precision;
  256.  
  257.     curveprecision(curve_precision);
  258.  
  259.     draw_display();
  260.     
  261.     remake_precision_menu();
  262.     remake_options_menu();
  263.     remake_curve_menu();
  264. }
  265.  
  266.  
  267. /*
  268.  * Changes the motion speed to that selected by the user.
  269.  */
  270. void change_speed(int new_speed)
  271. {
  272.     speed = new_speed;
  273.  
  274.     remake_speed_menu();
  275.     remake_options_menu();
  276.     remake_curve_menu();
  277. }
  278.  
  279.  
  280. /*
  281.  * Changes the line style used to draw the curves to that selected by
  282.  * the user.
  283.  */
  284. void change_style(int new_style)
  285. {
  286.     line_style = new_style;
  287.  
  288.     draw_display();
  289.     
  290.     remake_style_menu();
  291.     remake_options_menu();
  292.     remake_curve_menu();
  293. }
  294.  
  295.  
  296.  
  297. void change_whizbang(int new_whizbang)
  298. {
  299.     whizbang = new_whizbang;
  300.  
  301.     create_whizbang(whizbang);
  302.  
  303.     draw_active = TRUE;
  304.     draw_display();
  305.     
  306.     remake_whizbang_menu();
  307.     remake_options_menu();
  308.     remake_curve_menu();
  309. }
  310.  
  311.  
  312.  
  313. /*
  314.  * Sets the three dimensional viewing transformation and sets up depth
  315.  * cuing. DOES NOT PRESERVE THE CURRENT MATRX. BE SURE TO PUSHMATRIX
  316.  * IF YOU NEED TO SAVE IT.
  317.  */
  318. void set_three_d_view(void)
  319. {
  320.     /* Perspecive, 3D view:
  321.         40 degree field of view,
  322.         aspect maintained,
  323.         clip around -1 to +1 cube, allow for rotation,
  324.         move eye back */
  325.     perspective(400, aspect, 4.0 - fsqrt(3), 5.0 + fsqrt(3));
  326.     translate(0.0, 0.0, -5.0);
  327.     if (hardware != ECLIPSE8)
  328.     {
  329.         depthcue(TRUE);    
  330.     }
  331. }
  332.  
  333.  
  334. /*
  335.  * Sets the two dimensional viewing transformation.
  336.  * DOES NOT PRESERVE THE CURRENT MATRX. BE SURE TO PUSHMATRIX
  337.  * IF YOU NEED TO SAVE IT.
  338.  */
  339. void set_two_d_view(void)
  340. {
  341.     display_mode = TWO_D;
  342.     /* Orthographic, 2D view. Ignores z values */
  343.     ortho(-1.0, 1.0, -1.0, 1.0, -2.0, 2.0);
  344.     depthcue(FALSE);
  345. }
  346.